# Maintainer: umarcor <unai.martinezcorral@ehu.eus>

_realname=iverilog
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=12.0.r8793.96df23c5
pkgrel=3
pkgdesc="Icarus Verilog, is a Verilog simulation and synthesis tool (mingw-w64)"
arch=('any')
url="http://iverilog.icarus.com/"
license=('GPLv2+')
groups=("${MINGW_PACKAGE_PREFIX}-eda")
depends=("${MINGW_PACKAGE_PREFIX}-bzip2"
         "${MINGW_PACKAGE_PREFIX}-gcc"
         "${MINGW_PACKAGE_PREFIX}-readline")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-ghostscript"
             'git')

# NOTE: MSYS2 support was improved/fixed in 'master' (2020/12/04).
# When 12.0 is tagged/released, this should be changed to use a tarball instead.
_commit="96df23c"
source=("${_realname}::git://github.com/steveicarus/iverilog.git#commit=${_commit}")
sha256sums=('SKIP')

pkgver() {
  cd "${srcdir}/${_realname}"
  printf "12.0.r%s.%s" "$(git rev-list --count "${_commit}")" "$(git rev-parse --short "${_commit}")"
}

prepare() {
  cd "${srcdir}/${_realname}"
  sh autoconf.sh
}

build() {
  cd "${srcdir}/${_realname}"
  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST}
  make
}

check() {
  cd "${srcdir}/${_realname}"
  make check
#  git clone git://github.com/steveicarus/ivtest.git
#  cd ivtest
#  ./regress
}

package() {
  cd "${srcdir}/${_realname}"
  make DESTDIR="${pkgdir}" install
  mkdir -p "${pkgdir}${MINGW_PREFIX}/share/doc/${_realname}"
  mv "${pkgdir}${MINGW_PREFIX}"/*.pdf "${pkgdir}${MINGW_PREFIX}/share/doc/${_realname}"

  _licenses="${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}"
  mkdir -p "${_licenses}"
  install -m 644 COPYING "${_licenses}"
}
